package programmingChallenges.chap2;

public class MineSweeper {

	public static void main(String args[]) {
		
		Integer map[][] = {
				{-1,  0, 0, 0, 0},
				{ 0,  0, 0, 0, 0},
				{ 0, -1, 0, -1, 0},
				{ 0,  0, 0, 0, 0},
				{ -1,  0, 0, -1, 0}
		};
/*		Integer map[][] = {
				{-1,  0, 0, 0},
				{ 0,  0, 0, 0},
				{ 0, -1, 0, -1},
				{ 0,  0, 0, 0}
		};
*/		
		for (int i=0; i<map.length; i++) {
			
			for (int k=0; k<map[i].length; k++) {
				
				if (map[i][k] == -1) {
					
					// Check Edge
					if (i > 0 && map[i-1][k] != -1)
						map[i-1][k]++;
					if (k > 0 && map[i][k-1] != -1)
						map[i][k-1]++;
					if (k < 3 && map[i][k+1] != -1)
						map[i][k+1]++;
					if (i < 3 && map[i+1][k] != -1)
						map[i+1][k]++;
				}
				
			}
			
		}
		
		
		
		
		// Print Map
		for (int i=0; i<map.length; i++) {
			
			for (int k=0; k<map[i].length; k++) {
				System.out.print(map[i][k] + " ");
			}
			System.out.println();
		}
			
	}
}
